// 为reg-btn 绑定事件
document.getElementById("reg-btn").addEventListener("click", function () {
    let btn = this;
    btn.innerHTML = "注册中...";
    btn.disabled = true;
    // 获取用户输入的用户名
    const username = document.getElementById("Username-reg").value;
    // 获取用户输入的密码
    const password = document.getElementById("Password-reg").value;
    fetch(`http://${_HOST_}:${_PORT_}/register`, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({
            userName: username,
            password: password
        })
    })
        .then(response => response.json()) // 将响应体解析为 JSON
        .then(data => {
            // 恢复按钮点击
            btn.disabled = false;
            btn.innerHTML = "注册！";
            window.clickBtn.registerSuccess(username, data.userId, data.token);
        })
        .catch(error => {
            btn.innerHTML = error.toString();
        });
})